
#delimit ;


*     ****************************************************************  *;
*     Estimate Model: Y = b0 + b1X + b2Z + b3XZ + (b4-b11)Controls + epsilon  *;
*     ****************************************************************  *;



*     ****************************************************************  *;
*       Generate the values of Z for which you want to calculate the    *;
*       marginal effect (and standard errors) of X on Y.                *;
*     ****************************************************************  *;

egen zmin = min (Fearon2);
egen zmax = max(Fearon2);
gen z0 = (((_n-1)/(20-1))*(zmax-zmin))+zmin in 1/20;
generate MV=z0;

*     ****************************************************************  *;
*       Grab elements of the coefficient and variance-covariance matrix *;
*       that are required to calculate the marginal effect and standard *;
*       errors.                                                         *;
*     ****************************************************************  *;

matrix b=e(b); 
matrix V=e(V);
 
scalar b9=b[1,9]; 
scalar b10=b[1,10];
scalar b11=b[1,11];


scalar varb9=V[9,9]; 
scalar varb10=V[10,10]; 
scalar varb11=V[11,11];

scalar covb9b11=V[9,11]; 
scalar covb9b11=V[10,11];


*     ****************************************************************  *;
*       Calculate the marginal effect of X on Y for all MV values of    *;
*       the modifying variable Z.                                       *;
*     ****************************************************************  *;

gen conb=b9+b11*MV;


*     ****************************************************************  *;
*       Calculate the standard errors for the marginal effect of X on Y *;
*       for all MV values of the modifying variable Z.                  *;
*     ****************************************************************  *;

gen conse=sqrt(varb9+varb11*(MV^2)+2*covb9b11*MV); 


*     ****************************************************************  *;
*       Generate upper and lower bounds of the confidence interval.     *;
*       Specify the significance of the confidence interval.            *;
*     ****************************************************************  *;

gen a=1.96*conse;
 
gen upper=conb+a;
 
gen lower=conb-a;

*     ****************************************************************  *;
*       Graph the marginal effect of X on Y across the desired range of *;
*       the modifying variable Z.  Show the confidence interval.        *;
*     ****************************************************************  *;

graph twoway line conb   MV, clwidth(medium) clcolor(blue) clcolor(black)
        ||   line upper  MV, clpattern(dash) clwidth(thin) clcolor(black)
        ||   line lower  MV, clpattern(dash) clwidth(thin) clcolor(black)
        ||   ,   
		 xlabel(, labsize(5)) 
             ylabel(, labsize(5))
		 legend(off)
             yline(0, lcolor(black))   
             xtitle(Linguistic-Income Cross-Cuttingness, size(4)  )
             xsca(titlegap(2))
             ysca(titlegap(2))
             ytitle("Marginal Effect of Linguistic Fractionaliztion", size(4))
             scheme(s2mono) graphregion(fcolor(white));
             
*     ****************************************************************  *;
*                 Figure can be saved in a variety of formats.          *;
*     ****************************************************************  *; 

    


*     ****************************************************************  *;
*                                   THE END                             *;
*     ****************************************************************  *;


drop  zmin zmax z0 MV conb conse a upper lower;
